package com.bjc.sdx.activity;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.bjc.sdx.R;
import com.bjc.sdx.adapter.MyPagerAdapter;
import java.util.ArrayList;
import java.util.List;

public class ViewPagerActivity extends Activity {
    private View view1, view2, view3, view4;
    private ViewPager viewPager;  //对应的viewPager
    private List<View> viewList;//view数组

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.viewpager_main);
        // 从布局中拿到viewpage对象
        viewPager = (ViewPager) findViewById(R.id.viewpager);
        LayoutInflater inflater = getLayoutInflater();
        view1 = inflater.inflate(R.layout.viewpager_layout1, null);
        view2 = inflater.inflate(R.layout.viewpager_layout2, null);
        view3 = inflater.inflate(R.layout.viewpager_layout3, null);
        view4 = inflater.inflate(R.layout.gridview_layout, null);

        viewList = new ArrayList<View>();// 将要分页显示的View装入数组中
        viewList.add(view1);
        viewList.add(view2);
        viewList.add(view3);
        viewList.add(view4);

        PagerAdapter pagerAdapter = new MyPagerAdapter(viewList);
        viewPager.setAdapter(pagerAdapter);
    }
}
